// components/food-card/FoodCard.js
Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },

  externalClasses: [
    'custom-class',
    'thumb-class',
    'title-class',
    'desc-class',
    'price-class'
  ],

  /**
   * 组件的属性列表
   */
  properties: {
    thumb: String,
    thumbMode: {
      type: String,
      value: 'aspectFit'
    },
    lazyLoad: Boolean,

    title: String,
    desc: String,

    currency: {
      type: String,
      value: '¥',
    },

    price: {
      type: String,
      observer: 'updatePrice'
    },
    unit: {
      type: String,
      value: '个'
    },
    useCartSlot: {
      type: Boolean,
      value: true
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    integerStr: '',
    decimalStr: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    updatePrice() {
      const { price } = this.data;
      const priceArr = price.toString().split('.')
      this.setData({
        integerStr: priceArr[0],
        decimalStr: priceArr[1] ? `.${priceArr[1]}` : ''
      })
    }
  },

  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
    ready: function () {
    }
  },
})
